package edu.mapi.ir.controllers;

import java.awt.geom.Point2D;

/**
 * @author ZP
 */
public class GoToController extends SequenceController {

	double tx;
	double ty;
	
	public GoToController(double startX, double startY, double targetX, double targetY) {
		this.tx = targetX;
		this.ty = targetY;
		double angle = Math.atan2(targetY-startY, targetX-startX);
		double dist = Point2D.distance(startX, startY, targetX, targetY);
		
		angle = Math.toDegrees(angle);
		
		/*System.out.println("BEFORE: "+angle);
		
		while (angle > 180)
			angle -= 360;
		while (angle < -180)
			angle += 360;
		
		System.out.println("AFTER : "+angle);
		*/
		setControllers(new AbstractController[] {
				new StopController(),
				new RotateController(angle),
				new WalkController(dist)
		});
	}
	
	@Override
	public String getName() {
		return "Goto("+tx+","+ty+")";
	}
}
